
package net.swa.dewei.web.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Required;

import net.swa.dewei.beans.entity.District;
import net.swa.system.service.ICommonService;
import net.swa.system.web.action.AbstractBaseAction;

/**
 * 由于数据量不大暂时该功能为前台实现
 * @author dawei
 *
 */
public class DistrictAction extends AbstractBaseAction
{
    private static final long serialVersionUID = -985277678565361630L;

    private ICommonService commonService;

    /**区域的父节点**/
    private String pid;

    public ICommonService getCommonService()
    {
        return commonService;
    }

    @Required
	@Resource
    public void setCommonService(ICommonService commonService)
    {
        this.commonService = commonService;
    }

    public String getPid()
    {
        return pid;
    }

    public void setPid(String pid)
    {
        this.pid = pid;
    }

    //根据市查询县 父节点名称
    public String queryByParentId() throws Exception
    {
        HttpServletRequest r = getRequest();
        pid = r.getParameter("filter[filters][0][value]");
        List<District> list = commonService.search(District.class, new String[]{"pname","level"}, new Object[]{pid,3});
        outJson(list);
        return null;
    }

    //根据省查询市  父节点名称
    public String queryByProvince() throws Exception
    {
        HttpServletRequest r = getRequest();
        pid = r.getParameter("filter[filters][0][value]");
        List<District> list = commonService.search(District.class, new String[]{"pname","level"}, new Object[]{pid,2});
        outJson(list);
        return null;
    }
    
    //根据省查询市  父节点名称
    public String queryCityByProvince() throws Exception
    {
        HttpServletRequest r = getRequest();
        pid = r.getParameter("pname");
        List<District> list = commonService.search(District.class, new String[]{"pname","level"}, new Object[]{pid,2});
        outJson(list);
        return null;
    }
    
  //根据省查询市  父节点名称
    public String queryTownByCity() throws Exception
    {
        HttpServletRequest r = getRequest();
        pid = r.getParameter("pname");
        List<District> list = commonService.search(District.class, new String[]{"pname","level"}, new Object[]{pid,3});
        outJson(list);
        return null;
    }
	
	/**根据id查询**/
	public String queryByParentCode() throws Exception
    {
        HttpServletRequest r = getRequest();
        pid = r.getParameter("filter[filters][0][value]");
        List<District> list = commonService.search("pid", pid, District.class);
        outJson(list);
        return null;
    }

    public String queryRoots() throws Exception
    {
        //省的父节点为“0”
        List<District> list = commonService.search("pid", "0", District.class);
        outJson(list);
        return null;
    }
}
